package olga.gorbatiuk.record.comparators;

import static org.junit.Assert.*;

import java.util.Date;

import olga.gorbatiuk.record.Importance;
import olga.gorbatiuk.record.Record;

import org.junit.Test;

public class ByDateAndImportanceComparatorTest {


    @Test
    public void testCompare_FirstImportancePrecedesSecond_NegativeInteger() {
	Date date1 = new Date(2014, 06, 11);
	Date date2 = new Date(2015, 10, 12);
	Record record1 = new Record(date1, Importance.ONE, null, null);
	Record record2 = new Record(date2, Importance.THREE, null, null);
	int result = new ByDateComparator().compare(record1, record2);

	assertTrue(result < 0);
    }


    @Test
    public void testCompare_FirstImportanceFollowsSecond_PositiveInteger() {
	Date date1 = new Date(2015, 10, 12);
	Date date2 = new Date(2014, 06, 11);
	Record record1 = new Record(date1, Importance.ONE, null, null);
	Record record2 = new Record(date2, Importance.THREE, null, null);
	int result = new ByDateComparator().compare(record1, record2);

	assertTrue(result > 0);
    }

    @Test
    public void testCompare_FirstImportanceEqualsSecondAndDateEqualsToo_Zero() {
	Date date1 = new Date(2015, 10, 12);
	Date date2 = new Date(2015, 10, 12);
	Record record1 = new Record(date2, Importance.THREE, null, null);
	Record record2 = new Record(date1, Importance.THREE, null, null);

	int result = new ByDateComparator().compare(record1, record2);

	assertTrue(result == 0);
    }

    @Test
    public void testCompare_FirstImportanceEqualsSecondAndFirstDateFollowsSecond_PositiveInteger() {
	Date date1 = new Date(2015, 10, 12);
	Date date2 = new Date(2014, 01, 01);
	Record record1 = new Record(date1, Importance.THREE, null, null);
	Record record2 = new Record(date2, Importance.THREE, null, null);
	int result = new ByDateComparator().compare(record1, record2);

	assertTrue(result > 0);
    }

    @Test
    public void testCompare_FirstImportanceEqualsSecondAndFirstDatePrecedesSecond_NegstiveInteger() {
	Date date1 = new Date(2015, 10, 12);
	Date date2 = new Date(2014, 01, 01);
	Record record1 = new Record(date2, Importance.THREE, null, null);
	Record record2 = new Record(date1, Importance.THREE, null, null);
	int result = new ByDateComparator().compare(record1, record2);

	assertTrue(result < 0);
    }

}
